package cn.js.sangu.unitStore.service;

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.js.sangu.unitStore.entity.BomDe;
import cn.js.sangu.unitStore.mapper.BomDeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
public class BomDeService extends ServiceImpl<BomDeMapper, BomDe> {
    
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    /**
     * 清空表数据并重置自增ID，相当于truncate table操作
     * @return 是否操作成功
     */
    @Transactional
    public boolean truncateTable() {
        try {
            // 使用JdbcTemplate执行truncate table语句
            jdbcTemplate.execute("TRUNCATE TABLE bom_de");
            log.info("成功执行truncate table操作：bom_de");
            return true;
        } catch (Exception e) {
            log.error("执行truncate table操作失败：{}", e.getMessage());
            return false;
        }
    }
}
